﻿using System;
using System.Diagnostics;

namespace BattleFuryGameEngine.Time
{
    public static class BattleFuryTime
    {
        private static readonly long s_timeInitialized = Stopwatch.GetTimestamp();
        private static readonly double s_dInvFreq = 1.0 / (double)Stopwatch.Frequency;

        /// <summary>
        /// Get number of seconds since the application started
        /// </summary>
        public static double Now { get { return (double)(Stopwatch.GetTimestamp() - s_timeInitialized) * s_dInvFreq; } }

        /// <summary>
        /// Given seconds it will output a human friendly readable string (milliseconds if less than 60 seconds)
        /// </summary>
        public static string ToReadable(double seconds)
        {
            if (seconds > 60)
                return TimeSpan.FromSeconds(seconds).ToString();
            return (seconds * 1000.0).ToString("N2") + " ms";
        }

    }
}
